-
Notifications
You must be signed in to change notification settings - Fork 247
Enable NRT for Serialization namespace
#772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e7a31be to
8112d39
Compare
8112d39 to
1feaa17
Compare
minichma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's a lot of changes. LGTM, just a few thoughts. Skimmed over the code only very briefly though.
| var uriValue = Decode(a, attachment); | ||
| a.Uri = new Uri(uriValue, UriKind.RelativeOrAbsolute); | ||
|
|
||
| if (string.IsNullOrEmpty(uriValue)) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, returning null is the best option here, is it? Anyhow, it's a functional change, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have another look.
Not sure, returning null is the best option
I believe returning null to avoid throwing exceptions is overused in the codebase. Methods like TryGet(...) would have been a better alternative to returning a NRT. That said, enabling nullable has introduced more null checks but reduced overall coverage. However, this investment will pay off in terms of future code quality.
I've migrated projects to NRT several times, but this particular migration significantly exceeded my initial workload estimates. And that's without the unit tests still ahead of us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returned value can't be null here, will update the code.
Even if the uriValue were null, it would throw, then the exception is eaten up and null ist returned anyway
| try | ||
| { | ||
| var a = CreateAndAssociate() as Attendee; | ||
| if (CreateAndAssociate() is not Attendee a) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have different implementations using this pattern. Leave the current behavior for now.
|
|
||
| var uriString = Unescape(Decode(a, attendee)); | ||
|
|
||
| if (uriString == null) return a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the behavior is different to AttachmentSerializer, where we return null. I think, this way is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returned value can't be null here when args are not null.
|
|
||
| public override object Deserialize(TextReader tr) => Deserialize(tr.ReadToEnd()); | ||
| } | ||
| public override object? Deserialize(TextReader? tr) => tr != null ? Deserialize(tr.ReadToEnd()) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be allowed to pass null as the TextReader? Rather make it not nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of overriding the base method, SerializeToString(object? obj) which is nullable
| rawOffset = rawOffset.Substring(1, rawOffset.Length - 1); | ||
| } | ||
| // Supported formats | ||
| var formats = new[] { "hhmmss", "hhmm", "hh" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be declared as static property or field
| try | ||
| { | ||
| var name = Enum.GetName(typeof(DayOfWeek), ds.DayOfWeek); | ||
| value += name!.ToUpper().Substring(0, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If name is null, it would throw and be catched silently, which is ok, but not too readable. Handle explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, if (name == null) return null; is more readable
|



DataTypeSerializerFactorysimplifiedUtcOffsetSerializer.GetOffset(string)simplified